<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class CommentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //获取评价列表
        $data = DB::table('comment') -> get();

//        dd($data);
        foreach($data as $k=>$v)
        {
//            //取出用户member_id
            $member_id  = $v -> mem_id;
////            取出商品id :product_id
            $product_id =$v -> pro_id;
////
            $arr = DB::table('member') -> where('member_id',$member_id) -> first();
            $arr1 = DB::table('product') -> where('product_id',$member_id) -> first();
            $v->name = $arr->name;
            $v->title = $arr1->title;
        }
//        dd($data);
        return view('/admin/comment/index',['data'=>$data]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //处理显示或屏蔽
//        dd($id);
        $data = DB::table('comment') -> where('mem_id',$id) -> first();
        if($data->disabled==1)
        {
            $res = DB::table('comment')->where('mem_id',$id) -> update(['disabled'=>0]);
        }else{
           $res = DB::table('comment')->where('mem_id',$id) -> update(['disabled'=>1]);
        }
        if($res) {
            return redirect('/admin/comment')->with(['success' => '更改成功']);
        }
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
